// components/money_select/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  options: {
    multipleSlots: true
  },

  /**
   * 组件的初始数据
   */
  data: {
    salary: '', //薪资
    //薪资范围选择
    dbArray: [
      [''],
      ['1000']
    ],
    dbindex: [
      [0],
      [0]
    ],
    salaryOut: ["", ""],
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      this.init()
    },
    detached: function() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  
  /**
   * 组件的方法列表
   */
  methods: {
    init(){
      let arr = []
      for (let i = 0; i < 26; i++) {
        arr[i] = (i+1) + "000"
      }
      console.log(arr)
      // this.data.dbArray[0] = arr
      this.setData({
        ['dbArray[0]']:arr
      })
    },
    //薪资选择框确认
    bindMultiPickerChange: function (e) {
      this.setData({
        salary: `${e.detail.value[0]+1+'000'}-${e.detail.value[1]+e.detail.value[0]+1+'000'}`
      })
      console.log(this.data.salary)
      this.triggerEvent('change_money',this.data.salary)
    },
    //薪资选择框滚动
    bindMultiPickerColumnChange: function (e) {
      // console.log(e)
      let newSalary = this.data.salaryOut;
      let newArray = this.data.dbArray;
      let newIndex = this.data.dbindex;
      if (e.detail.column === 0) {
        switch (e.detail.value) {
          case -1:
            newArray[1] = [];
            newIndex[1] = 0;
            newSalary[0] = ['面议'];
            newSalary[1] = [];
            break;
          default:
            let dbArray = [];
            for (let i = 0; i < 7; i++) {
              dbArray[i] = i;
              dbArray[i] += 1;
            }
            for (let i = 0; i < dbArray.length; i++) {
              let num = Number(e.detail.value);
              dbArray[i] += num;
              dbArray[i] += "000"
            }
            newArray[1] = dbArray;
            newSalary[0] = newArray[0][e.detail.value];
            newSalary[1] = newArray[1][newIndex[1]];
            break;
        }
      } else {
        newSalary[1] = newArray[1][e.detail.value];
      }
      this.setData({
        salaryOut: newSalary,
        dbArray: newArray,
        dbindex: newIndex,
      })
    },
  }
})